package com.sgb.kjwl.viewmodel.shopping;


import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.UrlConfig;
import com.sgb.kjwl.model.entity.ShopInfoEntity;
import com.sgb.kjwl.repository.ShopCompanyInfoRepertory;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopCompanyInfoActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ShopCompanyModel extends BaseViewModel {
    private ShopCompanyInfoActivity activity;
    private ShopCompanyInfoRepertory repertory;
    private int page = 1;
    private int size = 10;
    public int total;

    public ShopCompanyModel(ShopCompanyInfoActivity activity, ShopCompanyInfoRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void shopDetail(Map map) {
        DialogHelper.showProgressDialog(activity, null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getShoppingCarAPI().shopDetail(map).enqueue(new Callback<BaseEntity<ShopInfoEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<ShopInfoEntity>> call, Response<BaseEntity<ShopInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null)
                    return;
                if ("ok".equals(response.body().getState())) {
                    if (response.body().getData() != null) {
                        activity.setData(response.body().getData());
                    }
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ShopInfoEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MToast.showToast(activity, t.getMessage());
            }
        });
    }
}
